<?php

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

class uploader extends WoniuController{
    public function doIndex(){
        echo '<form action="?uploader.upload" method="post" enctype="multipart/form-data"><input type="file" name="my_file"/><input type="submit" value="upload"></form>';
    }
    public function doUpload(){
        //实例化一个上传文件对象
        $uploader = new FileUploader();
        //设置表单input type=“file” 的name属性值。
        $uploader->setFormField('my_file');
        //允许上传的文件后缀
        $uploader->setExt(array('jpg', 'png','bmp','gif'));
        //允许上传的文件最大大小，单位KB
        $uploader->setMaxSize(2048);
        //$uploader->saveFile（$filename,$dir）
        //当$filename为null时，使用md5(sha1_file($tmp_file))作为文件名
        //当$dir非空时，文件的保存路径就是$dir.$filename
        //文件夹不存在的时候自动创建
        if (($file = $uploader->saveFile(null, 'upload/'))) {
            $this->message('上传成功:<b>'.$file.'</b>');
        } else {
            $err = $uploader->getErrorMsg();
            $this->message('上传失败：',$err); 
        }
    }
}